package xw.qxypt.modules.baseinfo.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import xw.qxypt.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import xw.qxypt.modules.baseinfo.entity.LhpHighwaySectionEntity;
import xw.qxypt.modules.baseinfo.service.LhpHighwaySectionService;
import xw.qxypt.common.utils.PageUtils;
import xw.qxypt.common.utils.R;



/**
 * 路段表
 *
 * @author xw
 * @email 
 * @date 2019-11-28 16:38:08
 */
@RestController
@RequestMapping("baseinfo/lhphighwaysection")
public class LhpHighwaySectionController {
    @Autowired
    private LhpHighwaySectionService lhpHighwaySectionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("baseinfo:lhphighwaysection:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = lhpHighwaySectionService.queryPage(params);

        return R.ok().put("page", page);
    }
    /**
     * 可用路段列表用于构件路段树
     */
    @RequestMapping("/waysectTree")
    public List<LhpHighwaySectionEntity> waysectTree(){
        List<LhpHighwaySectionEntity> list = lhpHighwaySectionService.waysectTree();
        return list;
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("baseinfo:lhphighwaysection:info")
    public R info(@PathVariable("id") String id){
        LhpHighwaySectionEntity lhpHighwaySection = lhpHighwaySectionService.getById(id);

        return R.ok().put("lhpHighwaySection", lhpHighwaySection);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("baseinfo:lhphighwaysection:save")
    public R save(@RequestBody LhpHighwaySectionEntity lhpHighwaySection){
        lhpHighwaySectionService.save(lhpHighwaySection);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("baseinfo:lhphighwaysection:update")
    public R update(@RequestBody LhpHighwaySectionEntity lhpHighwaySection){
        ValidatorUtils.validateEntity(lhpHighwaySection);
        lhpHighwaySectionService.updateById(lhpHighwaySection);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("baseinfo:lhphighwaysection:delete")
    public R delete(@RequestBody String[] ids){
        lhpHighwaySectionService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
